package com.qf.lanzhou.shop.api.service.impl;

import com.qf.lanzhou.shop.api.dao.OrderMapper;
import com.qf.lanzhou.shop.api.service.OrderService;
import com.qf.lanzhou.shop.pojo.entity.ParentsOrder;
import com.qf.lanzhou.shop.pojo.entity.ReceivingAddress;
import com.qf.lanzhou.shop.pojo.entity.SonOrder;
import com.qf.lanzhou.shop.pojo.qo.OrderAndAddress;
import com.qf.lanzhou.shop.pojo.qo.OrderParm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jack
 */
@Service
public class OrderServiceImpl implements OrderService {


    @Autowired
    private OrderMapper om;


    @Override
    public boolean insertParents(ParentsOrder parentsOrder) {
        int i = om.instrParents(parentsOrder);
        return getRelute(i);
    }

    private boolean getRelute(int i) {
        if (i==1){
            return false;
        }
        return true;
    }

    @Override
    public boolean insertSon(SonOrder order) {
        int i = om.instrSon(order);
        return  getRelute(i);
    }

    @Override
    public List<SonOrder> getSonsOrder(OrderParm orderParm) {
//        List<SonOrder> sonOrders = om.selectSonOrderByCart();
        List<SonOrder> sonOrders = om.selectSonOrderByCart(orderParm);
        return sonOrders;


    }

    @Override
    public ParentsOrder gerParentsOrder(Long id) {
        ParentsOrder parentsOrder = om.selectParentsOrder(id);
        return parentsOrder;
    }

    @Override
    public ReceivingAddress selectAddressByParentsId(Long id) {
        ReceivingAddress receivingAddress = om.selectAddressByParentsId(id);
        return receivingAddress;
    }

    @Override
    public ParentsOrder selectBySonOrderId(Long id) {
        ParentsOrder parentsOrder = om.selectBySonOrderId(id);
        return parentsOrder;
    }

    @Override
    public SonOrder selectSonOrderById(Long id) {
        SonOrder sonOrder = om.selectSonOrderById(id);
        return  sonOrder;
    }

    @Override
    public boolean selectAddress(OrderAndAddress orderAndAddress) {
        int i = om.selectAddress(orderAndAddress);
        return getRelute(i);
    }

    @Override
    public List<SonOrder> selectSonOrder(Long id) {
        List<SonOrder> sonOrders = om.selectSonOrder(id);
        return sonOrders;
    }

    @Override
    public String getSellerName(Long id) {
        String s = om.selectSellerNameBySellerId(id);
        return s;
    }

}
